﻿
#If Not (PocketPC Or Smartphone) Then

Imports System.Threading
Imports System.Net
Imports std

Public Class httpServer
    Inherits httpServerOld
    Private threads As threadpool = Nothing

    Public Overrides Sub [stop]()
        threads.stop()
        MyBase.[stop]()
    End Sub

    Protected Overrides Sub startcontext(ByVal context As HttpListenerContext)
        threads.insertJob(context)
    End Sub

    Public Overloads Function start(ByVal threadCount As Int64) As Boolean
        If MyBase.start() Then
            threads.start(threadCount)
            Me.threadCount = threadCount
            Return True
        Else
            Return False
        End If
    End Function

    Public Overrides Function start() As Boolean
        Return start(ifoper(threadCount() = 0, Environment.ProcessorCount << 3, threadCount()))
    End Function

    Public Property threadCount() As Int64
        Get
            Return threads.threadCount()
        End Get
        Set(ByVal value As Int64)
            threads.threadCount = value
        End Set
    End Property

    Public Sub New()
        MyBase.New()
        threads = New threadpool(AddressOf handle)
    End Sub
End Class

#End If
